package org.monkey.common.generator.formatter.module;

import cn.hutool.core.util.StrUtil;
import java.io.File;
import java.util.List;
import org.monkey.common.constant.util.MonkeyIoUtil;
import org.monkey.common.generator.entity.GeneratorConfig;
import org.monkey.common.generator.entity.JavaEntityInfo;
import org.monkey.common.generator.service.TemplateFileFormatter;
import org.monkey.common.generator.util.FormatUtil;
import org.springframework.stereotype.Component;

@Component
public class LogTemplateFileFormatter implements TemplateFileFormatter {

  private String templateStr = null;

  @Override
  public String getTemplateStr() {
    if(StrUtil.isBlank(templateStr)){
      templateStr = loadTemplateStr("log.ftl");
    }
    return templateStr;
  }

  @Override
  public String getTemplateName() {
    return "log";
  }

  @Override
  public void format(File rootDir, List<JavaEntityInfo> javaEntityInfos, GeneratorConfig config) {
    String logDir = rootDir.getAbsolutePath() + "/" + config.getModuleName()+"/src/main/resources";
    MonkeyIoUtil.batchCreateDirs(logDir);
    String pomFile = logDir + "/logback-spring.xml";
    FormatUtil.format(getTemplateStr(), pomFile, config.toParamMap(null));
  }
}
